class Monster {
    constructor(x, y) {
        this.x = x;
        this.y = y;
        this.radius = 20; // 将半径从40改为20，使直径从80变为40
        this.speed = 0.3;
        this.dx = this.speed;
        this.dy = this.speed;
    }

    update(canvasWidth, canvasHeight) {
        this.x += this.dx;
        this.y += this.dy;

        // 碰撞检测和反弹
        if (this.x - this.radius <= 0 || this.x + this.radius >= canvasWidth) {
            this.dx *= -1;
        }
        if (this.y - this.radius <= 0 || this.y + this.radius >= canvasHeight) {
            this.dy *= -1;
        }
    }

    draw(ctx) {
        ctx.beginPath();
        ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
        ctx.fillStyle = '#FF0000';
        ctx.fill();
        ctx.closePath();
    }

    // 获取怪物占据的网格坐标
    getGridPositions(cellSize) {
        const positions = [];
        const startX = Math.floor((this.x - this.radius) / cellSize);
        const startY = Math.floor((this.y - this.radius) / cellSize);
        const endX = Math.ceil((this.x + this.radius) / cellSize);
        const endY = Math.ceil((this.y + this.radius) / cellSize);

        for (let y = startY; y < endY; y++) {
            for (let x = startX; x < endX; x++) {
                positions.push({x, y});
            }
        }
        return positions;
    }
} 